import Vue from 'vue'
import Router from 'vue-router'
import index from '@/components/index'
import cart from '@/components/cart'
import item from '@/components/item'
import detail from '@/components/detail'
import mytest from '@/components/mytest'
import test from '@/components/test'
import zuoye from '@/components/zuoye'
import register from '@/components/register'
import myheader from '@/components/myheader'
import login from '@/components/login'
import mybody from '@/components/mybody'
import md_register from '@/components/md_register'
import md_login from '@/components/md_login'
import myprofile from '@/components/myprofile'
import mypics from '@/components/mypics'
import md_file from '@/components/md_file'
import md_goods from '@/components/md_goods'
import addgoods from '@/components/addgoods'
import editgood from '@/components/editgood'
import md_addgoods from '@/components/md_addgoods'
import goodall from '@/components/goodall'
import search from '@/components/search'

Vue.use(Router)

var routes = [
        {
          path:'/',
          name:'index',
          component:index
        },
        {
          path:'/cart',
          name:'cart',
          component:cart
        },
        {
          path:'/item',
          name:'item',
          component:item
        },
        {
          path:'/detail',
          name:'detail',
          component:detail
        },
        {
          path:'/mytest',
          name:'mytest',
          component:mytest
        },
          {
          path:'/test',
          name:'test',
          component:test
        },
        {
          path:'/zuoye',
          name:'zuoye',
          component:zuoye
        },
          {
          path:'/register',
          name:'register',
          component:register
        },
            {
          path:'/myheader',
          name:'myheader',
          component:myheader
        },
              {
          path:'/login',
          name:'login',
          component:login
        },
        {
          path:'/mybody',
          name:'mybody',
          component:mybody
        },
          {
          path:'/md_register',
          name:'md_register',
          component:md_register
        },
            {
          path:'/md_login',
          name:'md_login',
          component:md_login
        },
              {
          path:'/md_file',
          name:'md_file',
          component:md_file
        },
            {
          path:'/search',
          name:'search',
          component:search
        },
        //拦截器的使用
        {
          path:'/myprofile',
          name:'myprofile',
          component:myprofile,
          beforeEnter:(to,from,next) =>{

            //判断用户是否登录
            if (localStorage.getItem('username')){

              console.log('已登陆');
              next()
            }else {
              console.log('未登录');
              next('./login');
            }

          }
        },
              {
          path:'/mypics',
          name:'mypics',
          component:mypics
        },
        {
          path:'/md_goods',
          name:'md_goods',
          component:md_goods
        },
          {
          path:'/addgoods',
          name:'addgoods',
          component:addgoods
        },
            {
          path:'/editgood',
          name:'editgood',
          component:editgood
        },
              {
          path:'/md_addgoods',
          name:'md_addgoods',
          component:md_addgoods
        },
        {
          path:'/goodall',
          name:'goodall',
          component:goodall
        },



]

export default new Router({
  routes:routes,
  mode:'history'   /*hash*/
})
